package com.shanling.shanlingcontroller.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by weiyu on 2018/8/6.
 */

public class PreferenceUtil {
    private static SharedPreferences sp;
    private static PreferenceUtil instance;
    private static final String APP_TOKEN= "appToken";
    private static final String SESSIONID = "sessionId";
    private static final String USER_NAME="username";
    private static final  String PASSWORD="password";
    private static final String  IS_FRIST="frist";
    private static final String  IS_CONNECTED="isconnected";
    private static  final String BLENAME="ble_name";
    private static final String     BLETYPE="ble_type";
    private static  final String ALEXA_LANGUAGE_POSTION="language_postion";
    private static final String BLE_MAC="ble_mac";
    private static final String PLAY_MODE = "play_mode";
    private static final String PLAY_POSITION = "play_position";
    private static final String POSITION = "position";
    private static final String MUSIC_ID = "music_id";
    private static final String A2DPSTATE="a2dp_state";
    private static final String FILTER="filter";
    private PreferenceUtil(Context context) {
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }

    public static PreferenceUtil getInstance(Context context) {
        if(instance == null) {
            synchronized (PreferenceUtil.class) {
                if(instance == null) {
                    instance = new PreferenceUtil(context.getApplicationContext());
                }
            }
        }
        return instance;
    }

    /**
     * 保存/获取 APPtoken
     *
     * @param token
     */
    public void setAppToken(String token) {
        sp.edit().putString(APP_TOKEN, token).apply();
    }
    public String getAppToken() {
        return sp.getString(APP_TOKEN, "");
    }



    /**
     * 保存/获取 APP会话id
     *
     * @param sessionId
     */
    public void setSessionId(String sessionId) {
        sp.edit().putString(SESSIONID, sessionId).apply();
    }
    public String getSessionId() {
        return sp.getString(SESSIONID, "0");
    }

    /**
     * 保存/获取 用户名
     *
     * @param name
     */
    public void setUserName(String name) {
        sp.edit().putString(USER_NAME, name).apply();
    }
    public String getUserName() {
        return sp.getString(USER_NAME, "");
    }

    /**
     * 保存/获取 用户密码
     *
     * @param password
     */
    public void setPassword(String password) {
        sp.edit().putString(PASSWORD, password).apply();
    }
    public String getPassword() {
        return sp.getString(PASSWORD, "");
    }
    /**
     * 保存/获取 用户是否进入过guide页面
     *
     * @param
     */
    public void setIsFrist(boolean frist) {
        sp.edit().putBoolean(IS_FRIST,frist).apply();
    }
    public boolean getIsFrist() {
        return sp.getBoolean(IS_FRIST, true);
    }







    //记录蓝牙名称
    public void setBleName(String name){
        sp.edit().putString(BLENAME,name).apply();
    }
    public String getBleName(){
       return  sp.getString(BLENAME,"");
    }


    //记录蓝牙类型
    public void setBleType(int type){
        sp.edit().putInt(BLETYPE,type).apply();
    }
    public int getBleType(){
        return  sp.getInt(BLETYPE,1);
    }


    //记录alexa 语言
    public void setLanguage(int postion){
        sp.edit().putInt(ALEXA_LANGUAGE_POSTION,postion).apply();
    }
    public int getLanguage(){
        return  sp.getInt(ALEXA_LANGUAGE_POSTION,0);
    }


    //记录blemac地址
    public void setBleMac (String mac){
        sp.edit().putString(BLE_MAC,mac).apply();
    }
    public String  getBleMac(){
        return  sp.getString(BLE_MAC,"");
    }




    //记录播放模式
    public void setPlayMode(int playMode){
        sp.edit().putInt(PLAY_MODE,playMode).apply();
    }
    public int getPlayMode(){
        return  sp.getInt(PLAY_MODE,0);
    }


    public void setPlayPosition(int position){
        sp.edit().putInt(PLAY_POSITION,position).apply();
    }
    public int getPlayPostion(){
        return  sp.getInt(PLAY_POSITION,0);
    }



    public void setPosition(long position){
        sp.edit().putLong(POSITION,position).apply();
    }
    public long getPostion(){
        return  sp.getLong(POSITION,0L);
    }



    public void setMusicId(String musicId){
        sp.edit().putString(MUSIC_ID,musicId).apply();
    }
    public String getMusicId(){
        return  sp.getString(MUSIC_ID,"");
    }



    //记录蓝牙a2dp是否连接
    public void setA2dpstate(boolean isConnected){
        sp.edit().putBoolean(A2DPSTATE,isConnected).apply();
    }

    public boolean getA2dpstate(){
        return   sp.getBoolean(A2DPSTATE,false);
    }



    public void setFilter(String filter){
        sp.edit().putString(FILTER,filter).apply();
    }
    public String getFilter(){
        return  sp.getString(FILTER,"1");
    }


























}
